/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spring.controlador;



import com.spring.entidades.*;
import com.spring.servicios.*;
import java.util.Collections;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;




@Controller
public class Controlador {

    @Autowired
    private servicioRegistrador regdao;
    @Autowired
    private servicioTipoRegistrador tregdao;
    @Autowired
    private servicioDeclarante decdao;
    @Autowired
    private servicioParentesco parentdao;
    @Autowired
    private servicioNacimiento nacdao;
    
    
    
    
    @RequestMapping(value = "/index.htm", method = RequestMethod.GET)
    public String index() {
        return "index";
    }

//************************************************************************************
//               L L A M A D A S    H I P E R V I N C U L O S
//************************************************************************************ 
    @RequestMapping(value = "/Registrador.htm", method = RequestMethod.GET)
    public String MenuRegistrador() {
        return "MenuRegistrador" ;
    }
    @RequestMapping(value = "/BRegistrador.htm", method = RequestMethod.GET)
    public String BRegistrador() {
        return "BuscarRegistrador" ;
    }
    @RequestMapping(value = "/MTipoRegistrador.htm", method = RequestMethod.GET)
    public String MenuTipoRegistrador() {
        return "MenuTipo" ;
    }
    
        @RequestMapping(value = "/BTRegistrador.htm", method = RequestMethod.GET)
    public String BTRegistrador() {
        return "BuscarTipo" ;
    }
    
    @RequestMapping(value = "/MDeclarante.htm", method = RequestMethod.GET)
    public String MenuDeclarante() {
        return "MenuDeclarante" ;
    }
    
   @RequestMapping(value = "/BDeclarante.htm", method = RequestMethod.GET)
    public String BDeclarante() {
        return "BuscarDeclarante" ;
    }
     
    @RequestMapping(value = "/MParentesco.htm", method = RequestMethod.GET)
    public String MenuParentesco() {
        return "MenuParentesco" ;
    }
    
   @RequestMapping(value = "/BParentesco.htm", method = RequestMethod.GET)
    public String BParentesco() {
        return "BuscarParentesco" ;
    }
   
   @RequestMapping(value = "/MNac.htm", method = RequestMethod.GET)
    public String MenuNac() {
        return "MenuRegistrarNac" ;
    }
    

   
//************************************************************************************
//                         R E G I S T R A D O R 
//************************************************************************************ 
    @RequestMapping(value = "/listar_Registrador.htm", method = RequestMethod.GET)
    public ModelAndView frmListadoRegistradores() {
        ModelAndView mv = new ModelAndView("lista_registradores");
        mv.addObject("Registrador",regdao.getListarRegistrador());
        return mv;
    }
      
      @RequestMapping(value = "/eliminar_Registrador.htm", method = RequestMethod.GET)
    public String eliminarRegistrador(@RequestParam String codigo) {

        return (regdao.EliminarRegistrador(codigo))?"exito":"error";
    }
      
     @RequestMapping(value = "/Buscar_Registrador.htm", method = RequestMethod.POST)
    public ModelAndView BuscarRegistrador(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("ver_Registrador");
        Registrador t = regdao.buscarRegistrador(codigo);
        mv.addObject("reg", t);
        return mv;
    }
    
    @RequestMapping(value = "/Ingresar_Registrador.htm", method = RequestMethod.GET)
    public ModelAndView frmInsertarRegistrador() {
        ModelAndView mv = new ModelAndView("IngresarRegistrador");
        Registrador t = new Registrador();
        mv.addObject("lista_tipo", tregdao.getListarTipoRegistrador());
        mv.addObject("RegistradorBB", t);
        return mv;
    }
    
    @RequestMapping(value = "/procesa_insertar_Registrador.htm", method = RequestMethod.POST)
    public ModelAndView procesaInsertarRegistrador1(@ModelAttribute("RegistradorBB") Registrador tr) {
       
        boolean b = regdao.insertarRegistrador(tr);
        ModelAndView mv = new ModelAndView("exito");
        return mv;
    }
    



      @RequestMapping(value = "/frm_actualizar_Registrador.htm", method = RequestMethod.GET)
    public ModelAndView frmActualizarRegistrador(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("IngresarRegistrador");
        Registrador t = regdao.buscarRegistrador(codigo);
        mv.addObject("lista_tipo", tregdao.getListarTipoRegistrador());
        mv.addObject("RegistradorBB", t);
        return mv;
    }    
      
      
    @RequestMapping(value = "/Listar_Tipo_Registrador.htm", method = RequestMethod.GET)
    public ModelAndView frmListadoTrabajadoresTipo() {
        ModelAndView mv = new ModelAndView("lista_registradores_tipo");
        mv.addObject("lista_tipos", tregdao.getListarTipoRegistrador());
        mv.addObject("tiporegBB", new TipoReg());
        return mv;
    }
    
    
     @RequestMapping(value = "/busca_por_tipo.htm", method = RequestMethod.POST)
    public ModelAndView procesaBuscadorTrabajador(@ModelAttribute("tiporegBB") TipoReg ttr) {
        ModelAndView mv = new ModelAndView("lista_registradores_tipo");
        mv.addObject("lista_tipos", tregdao.getListarTipoRegistrador());
        mv.addObject("registradores", regdao.getListarRegistradorTipo(ttr));
        mv.addObject("tiporegBB",ttr);
        return mv;
    }

//************************************************************************************
//               T I P O   R E G I S T R A D O R 
//************************************************************************************      

      
        @RequestMapping(value = "/Listar_Tipo.htm", method = RequestMethod.GET)
    public ModelAndView frmListadoTipoRegistradores() {
        ModelAndView mv = new ModelAndView("lista_TipoReg");
        mv.addObject("TRegistrador",tregdao.getListarTipoRegistrador());
        return mv;
    }  
      
       @RequestMapping(value = "/eliminar_TRegistrador.htm", method = RequestMethod.GET)
    public String eliminarTRegistrador(@RequestParam String codigo) {

        return tregdao.EliminarTipoRegistrador(codigo)?"exito":"error";
    }    
      
    @RequestMapping(value = "/Buscar_Tipo.htm", method = RequestMethod.POST)
    public ModelAndView BuscarTRegistrador(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("ver_TipoReg");
        TipoReg t = tregdao.buscarTipoRegistrador(codigo);
        mv.addObject("reg", t);
        return mv;
    }
      
    
     @RequestMapping(value = "/Ingresar_Tipo.htm", method = RequestMethod.GET)
    public ModelAndView frmInsertarTRegistrador() {
        ModelAndView mv = new ModelAndView("IngresarTipo");
        TipoReg t = new TipoReg();
        mv.addObject("TRegistradorBB", t);
        return mv;
    }
  
    @RequestMapping(value = "/procesa_insertar_TRegistrador.htm", method = RequestMethod.POST)
    public ModelAndView procesaInsertarTRegistrador(@ModelAttribute("TRegistradorBB") TipoReg tr) {
        boolean b = tregdao.insertarTipoRegistrador(tr);
        ModelAndView mv = new ModelAndView("exito");
        return mv;
    }
    
    
       @RequestMapping(value = "/frm_actualizar_TRegistrador.htm", method = RequestMethod.GET)
    public ModelAndView frmActualizarTRegistrador(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("IngresarTipo");
        TipoReg t = tregdao.buscarTipoRegistrador(codigo);
        mv.addObject("TRegistradorBB", t);
        return mv;
    }  
//************************************************************************************
//                         D E C L A R A N T E 
//************************************************************************************ 
    @RequestMapping(value = "/Listar_Declarante.htm", method = RequestMethod.GET)
    public ModelAndView frmListadoDeclarante() {
        ModelAndView mv = new ModelAndView("lista_Declarante");
        mv.addObject("Declarante",decdao.getListarDeclarante());
        return mv;
    }
      @RequestMapping(value = "/Eliminar_Declarante.htm", method = RequestMethod.GET)
    public String eliminarDeclarante(@RequestParam String codigo) {

        return (decdao.EliminarDeclarante(codigo))?"exito":"error";
    }
     @RequestMapping(value = "/Buscar_Declarante.htm", method = RequestMethod.POST)
    public ModelAndView BuscarDeclarante(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("ver_Declarante");
        Declarante t = decdao.buscarDeclarante(codigo);
        mv.addObject("reg", t);
        return mv;
    }
    @RequestMapping(value = "/Ingresar_Declarante.htm", method = RequestMethod.GET)
    public ModelAndView frmInsertarDeclarante() {
        ModelAndView mv = new ModelAndView("IngresarDeclarante");
        Declarante t = new Declarante();
        mv.addObject("lista_tipo", parentdao.getListarTipoParentesco());
        mv.addObject("DeclaranteBB", t);
        return mv;
    }
    @RequestMapping(value = "/procesa_insertar_Declarante.htm", method = RequestMethod.POST)
    public ModelAndView procesaInsertarDeclarante(@ModelAttribute("DeclaranteBB") Declarante tr) {
       
        boolean b = decdao.insertarDeclarante(tr);
        ModelAndView mv = new ModelAndView("exito");
        return mv;
    }

      @RequestMapping(value = "/frm_actualizar_Declarante.htm", method = RequestMethod.GET)
    public ModelAndView frmActualizarDeclarante(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("IngresarDeclarante");
        Declarante t = decdao.buscarDeclarante(codigo);
        mv.addObject("lista_tipo", parentdao.getListarTipoParentesco());
        mv.addObject("DeclaranteBB", t);
        return mv;
    }  
    
   //************************************************************************************
//               T I P O   P A R E  N T E S C O
//************************************************************************************      

      
        @RequestMapping(value = "/Listar_Parent.htm", method = RequestMethod.GET)
    public ModelAndView frmListadoParent() {
        ModelAndView mv = new ModelAndView("lista_Parentesco");
        mv.addObject("Parent",parentdao.getListarTipoParentesco());
        return mv;
    }  
      
       @RequestMapping(value = "/Eliminar_Parent.htm", method = RequestMethod.GET)
    public String eliminarParent(@RequestParam String codigo) {

        return parentdao.EliminarParentesco(codigo)?"exito":"error";
    }    
      
    @RequestMapping(value = "/Buscar_Parent.htm", method = RequestMethod.POST)
    public ModelAndView BuscarParent(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("ver_Parentesco");
        Parentesco t = parentdao.buscarParentesco(codigo);
        mv.addObject("reg", t);
        return mv;
    }
      
    
     @RequestMapping(value = "/Ingresar_Parent.htm", method = RequestMethod.GET)
    public ModelAndView frmInsertarParent() {
        ModelAndView mv = new ModelAndView("IngresarParentesco");
        Parentesco t = new Parentesco();
        mv.addObject("ParentBB", t);
        return mv;
    }
  
    @RequestMapping(value = "/procesa_insertar_Parent.htm", method = RequestMethod.POST)
    public ModelAndView procesaInsertarParent(@ModelAttribute("ParentBB")Parentesco tr) {
        boolean b = parentdao.insertarParentesco(tr);
        ModelAndView mv = new ModelAndView("exito");
        return mv;
    }
    
    
       @RequestMapping(value = "/frm_actualizar_Parent.htm", method = RequestMethod.GET)
    public ModelAndView frmActualizarParent(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("IngresarParentesco");
        Parentesco t = parentdao.buscarParentesco(codigo);
        mv.addObject("ParentBB", t);
        return mv;
    }   
    
       
       
       
      //************************************************************************************
//                 R E G I S T R A R   N A C I M I E N T O S  
//************************************************************************************ 
    @RequestMapping(value = "/Listar_Nac.htm", method = RequestMethod.GET)
    public ModelAndView frmListadoNac() {
        ModelAndView mv = new ModelAndView("lista_RegNac");
        mv.addObject("Nac",nacdao.getListarNac());
        return mv;
    }
      
      
    
    @RequestMapping(value = "/Ingresar_Nac.htm", method = RequestMethod.GET)
    public ModelAndView frmInsertarNac() {
        ModelAndView mv = new ModelAndView("IngresarRegistrarNac");
        ActaNacimiento t = new ActaNacimiento();
        t.setSexo("M");
        mv.addObject("lista_regis", regdao.getListarRegistrador());
        mv.addObject("lista_decla", decdao.getListarDeclarante());
        mv.addObject("NacBB", t);
        return mv;
    }
    
    @RequestMapping(value = "/procesa_insertar_Nac.htm", method = RequestMethod.POST)
    public ModelAndView procesaInsertarNac(@ModelAttribute("NacBB") ActaNacimiento tr) {
       
        boolean b = nacdao.insertarNac(tr);
        ModelAndView mv = new ModelAndView("exito");
        return mv;
    }

      @RequestMapping(value = "/frm_actualizar_Nac.htm", method = RequestMethod.GET)
    public ModelAndView frmActualizarNac(@RequestParam String codigo) {
        ModelAndView mv = new ModelAndView("IngresarRegistrarNac");
         ActaNacimiento t = nacdao.buscarNac(codigo);
        mv.addObject("lista_regis", regdao.getListarRegistrador());
        mv.addObject("lista_decla", decdao.getListarDeclarante());
        mv.addObject("NacBB", t);
        return mv;
    }     
       
      
}